package br.com.ss.seguranca.model.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

/**
 * Sistema generated by hbm2java
 */
@Entity
@Table(name = "sistema")
@NamedQueries({
	@NamedQuery(name = "Sistema.findAllSistemas", 
					query = "SELECT sis FROM Sistema sis"),
	@NamedQuery(name = "Sistema.findSistemaByUser", 
		              query = " SELECT sis FROM Sistema sis " +
		              		" join sis.roles role " +
		              		" join role.userRoles userRole " +
		              		" where userRole.user = :user "
			)
} )
public class Sistema implements java.io.Serializable {

	private Integer id;
	private String name;
	private Set<Role> roles = new HashSet<Role>(0);

	public Sistema() {
	}

	public Sistema(String name) {
		this.name = name;
	}

	public Sistema(String name, Set<Role> roles) {
		this.name = name;
		this.roles = roles;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "name", nullable = false, length = 60)
	@NotNull
	@Length(max = 60)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "sistema")
	public Set<Role> getRoles() {
		return this.roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

}
